import Vue from 'vue'
import dayjs from 'dayjs'

// 创建vue时间过滤器
Vue.filter("timeDate", function (value, format) {
  let date = ''
  if (value.length == 14) {
    date = value.slice(0, 4) + "-" + value.slice(4, 6) + "-" + value.slice(6, 8) + " " + value.slice(8, 10) + ":" + value.slice(10, 12) + ":" + value.slice(12, 14);
  } else if (value.length == 12) {
    date = value.slice(0, 4) + "-" + value.slice(4, 6) + "-" + value.slice(6, 8) + " " + value.slice(8, 10) + ":" + value.slice(10, 12);
  } else if (value.length == 10) {
    date = value.slice(0, 4) + "-" + value.slice(4, 6) + "-" + value.slice(6, 8) + " " + value.slice(8, 10);
  } else if (value.length == 8) {
    date = value.slice(0, 4) + "-" + value.slice(4, 6) + "-" + value.slice(6, 8);
  } else {
    date = value
  }

  date = new Date(date)
  return dayjs(date).format(format || "YYYY-MM-DD HH:mm:ss");
})